package edu.sctu.zhengsenwen.month201506.day20150616.network;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

/**
 * Created by user15 on 2015/6/18.
 */
public class HttpRequest {

    public static String getSend(String path) throws IOException {

        String result = "haha";
        BufferedReader input = null;

        URL url = new URL(path);
        URLConnection urlConnection = url.openConnection();

        //设置一般请求属性
        urlConnection.setRequestProperty("accept","***");
        urlConnection.setRequestProperty("content","&&");
        urlConnection.setRequestProperty("name","smile of the sun");

        urlConnection.connect();


        //用循环把代表请求属性的键值对放在容器中
        Map<String,List<String>> map = urlConnection.getHeaderFields();

        for(String key:map.keySet()){
            System.out.println(key+"  : "+ map.get(key));
        }


        input = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));

        String line;

        //
        while((line = input.readLine()) != null){
            result = result + line;
        }

        if(input != null){
            input.close();
        }

        return result;
    }
}
